package com.zhanqiao.controller;

import com.google.gson.Gson;
import com.zhanqiao.domain.VipBean;
import com.zhanqiao.service.SelectVipService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/addvip.action")
public class AddVipController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String  vname=req.getParameter("vname");
        String  vpwd=req.getParameter("vpwd");
        String  vsex=req.getParameter("vsex");
        String  vrestmoney=req.getParameter("vrestmoney");
        String  vphone=req.getParameter("vphone");
        VipBean vipBean=new VipBean();
        vipBean.setVname(vname);
        vipBean.setVpwd(vpwd);
        vipBean.setVsex(Integer.parseInt(vsex));
        vipBean.setVrestmoney(Integer.parseInt(vrestmoney));
        vipBean.setVphone(vphone);
        SelectVipService selectVipService = new SelectVipService();
        try {
            Integer i = selectVipService.addService(vipBean);
            Map message = new HashMap();
            System.out.println("i=" + i);
            if (i > 0) {
                message.put("msg", "开通成功");
            } else {
                message.put("msg", "开通失败");
            }
            String result = new Gson().toJson(message);
            resp.getWriter().write(result);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
